package com.jsle.financial.service;


import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import com.jsle.financial.dao.ResourcesDaoImpl;
import com.jsle.financial.domain.Resources;
import com.jsle.financial.manager.ResourcesManager;
import com.jsle.financial.util.Constants;
import com.jsle.financial.vo.Page;
import com.jsle.financial.vo.Result;
import com.sun.naming.internal.ResourceManager;
/**
 * ResourceService业务逻辑处理类
 * @author wisdying
 * @date 2012-10-27
 */
@Service
public class ResourcesServiceImpl implements ResourcesService{

	private Log log = LogFactory.getLog(ResourcesServiceImpl.class);
	
	@Resource
	private ResourcesManager ResourcesManager;
	@Resource
	private ResourcesDaoImpl ResourcesDao;
	
	/**
	 * 根据page查询Resources
	 */
	public Result queryResourceByPage(Page page, Resources resource) {
		Result result = new Result();
		try {
			result = ResourcesDao.queryResourceByPage(page,resource);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_QUERY_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_QUERY_SERVICE_ERROR_MESSAGE, "Query Users by page"));
			log.error("query users by page error## "+ e.getMessage());
		}
		return result;
	}
	
	/**
	 * 新增一资源
	 * @param Resource
	 * @return
	 */
	public Result addResource(Resources resource){
		Result result = new Result();
		try {
			result = ResourcesManager.addResource(resource);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "Resource"));
			log.error("new Resource error## "+ e.getMessage());
		}
		return result;
	}
	/**
	 * 删除一资源
	 * @param Resource
	 * @return
	 */
	public Result delResources(Resources resources){
		Result result = new Result();
		try {
			result = ResourcesManager.delResources(resources);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_DEL_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_DEL_SERVICE_ERROR_MESSAGE, "Resource"));
			log.error("del Resource error## "+ e.getMessage());
		}
		return result;
	}
	/**
	 * 更新一资源
	 * @param Resource
	 * @return
	 */
	public Result updateResource(Resources resources){
		Result result = new Result();
		try {
			result = ResourcesManager.updateResource(resources);

		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_UPDATE_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_UPDATE_SERVICE_ERROR_MESSAGE, "Resource"));
			log.error("update Resource error## "+ e.getMessage());
		}
		return result;
	}
	
	/**
	 * 根据code获取资源
	 * @param resources
	 * @return
	 */
	public Result queryResourceByResourceCode(Resources resources){
		Result result = new Result();
		try {
			result = ResourcesDao.queryResourceByResourceCode(resources);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_QUERY_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_QUERY_SERVICE_ERROR_MESSAGE, "Resource"));
			log.error("query Resource error## "+ e.getMessage());
		}
		return result;
	}
}
